//获取应用实例
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list: [],
    isShowMenu: false,
    curMenu: '需求汇总',
    menuList: null,
    storeListData: app.globalData.storeListData,
    request_common_para:app.globalData.request_common_para,
    index:0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    app.intiSysConfigData()
    let store_name = app.globalData.request_common_para.store_name;
    let storeListData = app.globalData.storeListData
    let index = storeListData.indexOf(store_name)
    let request_common_para = app.globalData.request_common_para
    this.setData({
      menuList: app.globalData.menuListData,
      storeListData: app.globalData.storeListData,
      request_common_para: request_common_para,
      index:index
    })
    let data = this.data.request_common_para
    data.carModel=''
    data.store_name=store_name
    wx.request({
      url: app.getHost()+'/datalake/v1/userManages/moderType',
      data: data,
      method: "post",
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: res => {
        if (res.statusCode == 200) {
          this.setData({
            list: res.data.data
          })
        }
      },
      fail: function(res) {
        console.info("modeType err:" + res)
      },
      complete: function(res) {}
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },
  searchBox: function (e) {
    let index=this.data.index
    let data = this.data.request_common_para
    data.carModel = e.detail.value
    
    if(index!=0){
      data.store_name =this.data.storeListData[index]
    }
    wx.request({
      url: app.getHost()+'/datalake/v1/userManages/moderType',
      data: data,
      method: "post",
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: res => {
        if (res.statusCode == 200) {
          this.setData({
            list: res.data.data
          })
        }
      },
      fail: function (res) {
        console.info("modeType err:" + res)
      },
      complete: function (res) { }
    })
  },
   kindToggle: function (e) {
    var id = e.currentTarget.id, list = this.data.list;
    for (var i = 0, len = list.length; i < len; ++i) {
      if (list[i].index == id) {
        list[i].open = !list[i].open
      } else {
        list[i].open = false
      }
    }
    this.setData({
      list: list
    });
  },
  toggleMenuList: function (e) {
    let { isShowMenu } = this.data;

    this.setData({
      isShowMenu: !isShowMenu
    })
  },
  bindPickerChange: function (e) {
    this.setData({
      index: e.detail.value
    })
    let index = this.data.index
    let data = this.data.request_common_para
    data.carModel = this.data.carModel

    //if (index != 0) {
      data.store_name = this.data.storeListData[index]
    //}
    wx.request({
      url: app.getHost() + '/datalake/v1/userManages/moderType',
      data: data,
      method: "post",
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: res => {
        if (res.statusCode == 200) {
          this.setData({
            list: res.data.data
          })
        }
      },
      fail: function (res) {
        console.info("modeType err:" + res)
      },
      complete: function (res) { }
    })





  },
  navigatorPage: function (e) {
    let dataset = e.currentTarget.dataset;
    let pages = getCurrentPages();
    let currPage = pages[pages.length - 1];

    if ('/' + currPage.route == dataset.url) {
      return
    }

    this.setData({
      isShowMenu: false
    })
    wx.reLaunch({
      url: dataset.url
    })
  }
})